<template>
  <div>
    <div class="chunk">
      <a-form :form="form" id="update-form" :hideRequiredMark="true">
        <div class="header">
          <h3>一、报告信息</h3>
          <div class="operate">
            <a-button type="primary" @click="exportExcel">导出报告</a-button>
          </div>
        </div>
        <div class="form-main-content">
          <a-row :gutter="10">
            <a-col :span="8" class="form-item">
              <a-form-item label="报告编号">{{tableData.sn}}</a-form-item>
            </a-col>
            <a-col :span="8" class="form-item">
              <a-form-item label="报告名称">{{tableData.name}}</a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="10">
            <a-col :span="8" class="form-item">
              <a-form-item label="所属任务">
                <!-- <span v-if="">无</span> -->
                <span>
                  <router-link :to="'/orders/update/'">455646545645664</router-link>
                </span>
              </a-form-item>
            </a-col>
            <a-col :span="8" class="form-item">
              <a-form-item label="所属订单">
                <!-- <span v-if="">无</span> -->
                <span>
                  <router-link :to="'/orders/update/'">455646545645664</router-link>
                </span>
              </a-form-item>
            </a-col>
            <a-col :span="8" class="form-item">
              <a-form-item label="下单账号">{{tableData.task_id}}</a-form-item>
            </a-col>
            <a-col :span="8" class="form-item">
              <a-form-item label="账号用户">{{data.user_id}}</a-form-item>
            </a-col>
            <a-col :span="8" class="form-item">
              <a-form-item label="生成时间">{{tableData.created_at}}</a-form-item>
            </a-col>
          </a-row>
        </div>
      </a-form>
      <div class="relate-service">
        <h3>二、使用详情</h3>
        <a-row :gutter="10">
          <a-col :span="6" class="form-issue">
            <div>
              <h4>常见问题</h4>
              <ul>
                <li v-for="(v,i) in tags" :key="i">
                  <span class="inssue-left">{{i+1}}、{{v.name}} ：</span>
                  <span class="inssue-right">出现次数{{v.value}}次</span>
                </li>
              </ul>
            </div>
          </a-col>
          <a-col :span="18" class="form-issue">
            <div id="analyzeChart"></div>
          </a-col>
        </a-row>
      </div>
    </div>
    <div class="chunk">
      <div class="relate-service">
        <a-row :gutter="10">
          <a-col :span="6" class="form-issue">
            <div>
              <h4>常见问题</h4>
              <ul>
                <li v-for="(v,i) in datas.tags" :key="v.id">
                  <span class="inssue-left">{{i+1}}、{{v.name}} ：</span>
                  <span class="inssue-right">出现次数{{v.id}}次</span>
                </li>
              </ul>
            </div>
          </a-col>
          <a-col :span="18" class="form-issue">
            <div id="analyzeChartThe"></div>
          </a-col>
        </a-row>
      </div>
    </div>
    <div class="chunk">
      <div class="relate-service">
        <h3>三、标注详情</h3>
        <a-row :gutter="10">
          <a-col :span="24" class="form-issue">
            <div>
              <h4>导出订单统计报告查看所有标注信息</h4>
              <h4>标注样式 :</h4>
            </div>
          </a-col>
          <a-col :span="24">
            <table border="1" class="label-table">
              <tr>
                <td>标题</td>
                <td>{{datas.title}}</td>
              </tr>
              <tr>
                <td>地址</td>
                <td>{{datas.address}}</td>
              </tr>
              <tr>
                <td>坐标</td>
                <td>{{datas.geom}}</td>
              </tr>
              <tr>
                <td>面积</td>
                <td>{{datas.lp_size}}</td>
              </tr>
              <tr>
                <td>标签</td>
                <td>{{datas.title}}</td>
              </tr>
              <tr>
                <td>责任人</td>
                <td>{{datas.operator}}</td>
              </tr>
              <tr>
                <td>备注</td>
                <td>{{datas.letter}}</td>
              </tr>
              <tr>
                <td>标注图片</td>
                <td>
                  <img :src="datas.img" alt />
                </td>
              </tr>
              <tr>
                <td>台账日期</td>
                <td>{{datas.accountime}}</td>
              </tr>
              <tr>
                <td>
                  <span>台账信息</span>
                </td>
                <td>
                  <dl class="table-info">
                    <dt>
                      <img :src="datas.img" alt />
                    </dt>
                    <dd>{{datas.account}}</dd>
                  </dl>
                </td>
              </tr>
            </table>
          </a-col>
        </a-row>
      </div>
    </div>
  </div>
</template>

<script>
import { export_json_to_excel } from "@/utils/Export2Excel";
import { Row, Col, Card, Button, Form } from "ant-design-vue";
export default {
  components: {
    ARow: Row,
    ACol: Col,
    ACard: Card,
    AButton: Button,
    ACardMeta: Card.Meta,
    AForm: Form,
    AFormItem: Form.Item
  },
  data() {
    return {
      form: this.$form.createForm(this),
      tableData: [],
      data: [],
      datas: [],
      tags: []
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.http("get", `/report/view?id=${this.$route.params.id}`).then(res => {
        this.tableData = res;
        this.data = res.data;
        this.datas = res.data.data[0];
        var str = [];
        var name = [];
        var value = [];
        for (let k in res.tags) {
          str.push({
            name: k,
            value: res.tags[k]
          });
          name.push(k + "");
          value.push(res.tags[k]);
        }
        this.tags = str;
        this.echartsDate({ name: name, value: value }, this.datas.tags);
      });
    },
    exportExcel() {
      const tHeader = [
        "标题",
        "地址",
        "坐标",
        "面积",
        "标签",
        "责任人",
        "备注",
        "标注图片",
        "台账日期",
        "台账信息",
        "台账名称"
      ];

      var date = new Date();
      var data = [
        this.datas.title,
        this.datas.address,
        this.datas.geom,
        this.datas.lp_size,
        this.datas.title,
        this.datas.operator,
        this.datas.letter,
        this.datas.img,
        this.datas.accountime,
        this.datas.img,
        this.datas.account
      ];
      data = [data];
      let month = date.getMonth() + 1;
      setTimeout(
        () =>
          export_json_to_excel({
            header: tHeader,
            data,
            filename:
              date.getFullYear() + "-" + month + "-" + date.getDate() + "订单",
            autoWidth: true,
            bookType: "xlsx"
          }),
        300
      );
    },
    echartsDate(data, tags) {
      var str = {
        name: [],
        value: []
      };
      tags.map(v => {
        str.name.push(v.name);
        str.value.push(v.id);
      });
      var myChart = this.$echarts.init(document.getElementById("analyzeChart"));
      var myChartThe = this.$echarts.init(
        document.getElementById("analyzeChartThe")
      );

      var myAnalyze = document.getElementById("analyzeChart");
      var myAnalyzeThe = document.getElementById("analyzeChartThe");
      var option = {
        axisLabel: {
          color: "#fff"
        },
        color: ["#3398DB"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          },
          backgroundColor: "#fff",
          borderRadius: "0px",
          textStyle: {
            fontSize: 16,
            color: "black"
          },
          formatter: "{b} : {c}"
        },
        grid: {
          left: "6%",
          right: "6%",
          bottom: "0%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            name: "标注",
            data: data.name,
            axisTick: {
              alignWithLabel: true
            },
            axisLine: {
              lineStyle: {
                color: "rgb(107, 122, 134)"
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "数量",
            axisLine: {
              lineStyle: {
                color: "rgb(107, 122, 134)"
              }
            },
            splitLine: {
              lineStyle: {
                type: "filament",
                color: "rgb(12, 68, 121)"
              }
            }
          }
        ],
        series: [
          {
            type: "bar",
            barWidth: "43%",
            data: data.value,
            label: {
              normal: {
                show: true,
                position: "top",
                color: "#fff"
              }
            }
          }
        ]
      };
      var optionThe = {
        title: {
          text: "矢量图计算统计",
          x: "center",
          textStyle: {
            color: "#fff",
            fontWeight: "100",
            fontSize: 16
          }
        },
        axisLabel: {
          color: "#fff"
        },
        color: ["#3398DB"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          },
          backgroundColor: "#fff",
          borderRadius: "0px",
          textStyle: {
            fontSize: 16,
            color: "black"
          },
          formatter: "{b} : {c}"
        },
        grid: {
          left: "6%",
          right: "6%",
          bottom: "0%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            name: "区域",
            data: str.name,
            axisTick: {
              alignWithLabel: true
            },
            axisLine: {
              lineStyle: {
                color: "rgb(107, 122, 134)"
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "数量",
            axisLine: {
              lineStyle: {
                color: "rgb(107, 122, 134)"
              }
            },
            splitLine: {
              lineStyle: {
                type: "filament",
                color: "rgb(12, 68, 121)"
              }
            }
          }
        ],
        series: [
          {
            type: "bar",
            barWidth: "43%",
            data: str.value,
            label: {
              normal: {
                show: true,
                position: "top",
                color: "#fff"
              }
            }
          }
        ]
      };
      myChart.setOption(option);
      myChartThe.setOption(optionThe);

      myAnalyze.children[0].style.width = "100%";
      myAnalyze.children[0].children[0].style.width = "100%";

      myAnalyzeThe.children[0].style.width = "100%";
      myAnalyzeThe.children[0].children[0].style.width = "100%";
      window.onresize = function() {
        myChart.resize();
        myChartThe.resize();
      };
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped >
@import "./../../assets/scss/mixin";
.header {
  @include fj();
  margin-bottom: 10px;
  .operate {
    .ant-btn + .ant-btn {
      margin-left: 40px;
    }
  }
}
.img-displayed {
  img + img {
    margin-left: 20px;
  }
}
.form-issue {
  h4 {
    font-size: 15px;
    text-indent: 0.5em;
    margin-bottom: 5px;
    margin-top: 17px;
  }
  ul li {
    text-indent: 1.3em;
    line-height: 30px;
  }
  #analyzeChart {
    width: 100%;
    height: 450px;
  }
}
.chunk {
  #analyzeChartThe {
    width: 100%;
    height: 450px;
  }
  margin-bottom: 10px;
  // border-bottom: 1px solid red;
  padding-bottom: 50px;
}
.label-table {
  margin-left: 40px;
  margin-top: 10px;
  border: 1px solid black;
  font-size: 14px;
  line-height: 35px;
  img {
    width: 220px;
    margin: 20px;
    margin-left: 0;
  }
  tr td:nth-child(1) {
    width: 200px;
    text-align: center;
  }
  tr td:nth-child(2) {
    width: 600px;
    padding-left: 20px;
  }
  .table-info {
    width: 220px;
    text-align: center;
    img {
      margin-bottom: 0;
    }
    margin-bottom: 10px;
  }
  tr:last-child td:nth-child(1) {
    float: left;
    margin-top: 30px;
    border: 0;
  }
}
</style>